$(function(){
    list();

    //todo 展示下拉
    $('.layui-colla-title').click(function(){
        let result = $(this).attr('show');
        if(result == 1){
            let ref = $(this).next();
            ref.addClass('layui-show');
            $(this).attr('show',2);
        }else{
            $(this).next('.layui-colla-content').removeClass('layui-show');
            $(this).attr('show',1);
        }
    });

    //todo 添加
    $('#btn-add').click(function(){

        layOpen('添加币种','500px','400px','create.html')
    });

    $('.layui-colla-item span').click(function(){
        let cu_id = $(this).attr('ids');
        layOpen('编辑','500px','400px','edit.html?cu_id='+cu_id)
    })
});


function list(){
    let data = AjaxForm('admin/CurrencyList');
    let html ='';
    let show = '<h2 class="layui-colla-title show" show="1">';
    for (let i=0;i<data.length;i++){
        if(data[i].show === 2){
            show = '<h2 class="layui-colla-title noshow" show="1">'
        }
        let ref = data[i].son;
        let son = '';
        for (let f=0;f<ref.length;f++){
            let icon = '';
            let sonshow = `<span class="show" ids="${ref[f].cu_id}">`;
            if(ref[f].show === 2)sonshow = `<span class="noshow" ids="${ref[f].cu_id}">`;
            if(ref[f].type === 1)icon = '<icon class="layui-badge-dot"></icon>';
            son += `${sonshow}${ref[f].title}/usdt${icon}</span>&nbsp;`
        }
        html += `<div class="layui-colla-item">
                   ${show}${data[i].title}<i class="layui-icon layui-colla-icon"></i></h2>
                    <div class="layui-colla-content">
                       <p>${son}<span type="button" ids="${data[i].cu_id}" style="background: #1E9FFF;color: white;border: 1px solid #1E9FFF;border-radius: 5px">编辑</span></p>
                    </div>
                </div>`
    }
    $('.layui-card-body').html(html);

    $('.del').click(function(){
        let cu_id = $(this).attr('ids');
        layFirm('删除','admin/CurrencyDel',{cu_id:cu_id});
    })
}